package cn.jcby.app.lebu.controller;


import cn.jcby.app.lebu.controller.req.BasicListReq;
import cn.jcby.app.lebu.controller.res.MyAlbumListRes;
import cn.jcby.app.lebu.entity.UserAlbumEntity;
import cn.jcby.app.lebu.service.UserAlbumService;
import cn.jcby.app.lebu.utils.PageUtils;
import cn.jcby.app.lebu.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



/**
 * 相册
 *
 * @author lht
 * @email 
 * @date 2023-12-07 15:13:35
 */
@RestController
@RequestMapping("/album")
@Api(tags="相册")
public class UserAlbumController {
    @Autowired
    private UserAlbumService userAlbumService;

    /**
     * 列表
     */
    @PostMapping("/myList")
    @ApiOperation("我的相册列表")
    @ApiResponses({
          @ApiResponse(code = 200,message = "ok",response = MyAlbumListRes.class)
    })
    public Result list(@RequestBody BasicListReq params){
        try {
            PageUtils page = userAlbumService.queryPage(params);
            return Result.ok().put("data", page);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage()) ;
        }
    }


    /**
     * 信息
     */
 /*   @GetMapping("/info/{id}")
    @ApiOperation("详情")
    @ApiResponses({
         @ApiResponse(code = 200,message = "ok",response = UserAlbumEntity.class)
    })
    public Result info(@PathVariable("id") String id){
        try {
            UserAlbumEntity userAlbum = userAlbumService.getById(id);
            return Result.ok().put("data", userAlbum);
        }catch (Exception e){
            e.printStackTrace();
             return Result.error(e.getMessage()) ;
        }
    }*/

    /**
     * 保存
     */
   /* @PostMapping("/save")
    @ApiOperation("添加")
    public Result save(@RequestBody @Validated(Insert.class) UserAlbumEntity userAlbum,BindingResult bindingResult){
        try {
            ParamUtils.check(bindingResult);
            userAlbumService.add(userAlbum);
            return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage()) ;
        }
    }*/

    @PutMapping("/setAvatar")
    @ApiOperation("设置头像")
    public Result setAvatar(@RequestParam("id") String id){
        userAlbumService.setAvatar(id) ;
        return Result.ok() ;
    }
    /**
     * 修改
     */
    /*@PutMapping("/update")
    @ApiOperation("修改")
    public Result update(@RequestBody @Validated(Update.class) UserAlbumEntity userAlbum,BindingResult bindingResult){
        try {
          ParamUtils.check(bindingResult);
          userAlbumService.updateBy(userAlbum);
          return Result.ok();
        }catch (Exception e){
            e.printStackTrace();
            return Result.error(e.getMessage()) ;
        }
    }
*/
    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除")
    public Result delete(@PathVariable("id") String id){

        UserAlbumEntity userAlbum = userAlbumService.infoById(id) ;
        if(userAlbum == null){
            return Result.error("记录不存在") ;
        }
        userAlbumService.removeById(id);
        return Result.ok();
    }

}
